﻿#pragma once
#include <QObject>

#include "bdaqctrl.h"
#include "NewPCIDemoDefine.h"
#include "CoreData.h"
#include "ConfigData.h"

#define ONCE_DATA_LENGTH 1000
#define SAVE_DATA_LENGTH 10

using namespace Automation::BDaq;

class PCIControl  : public QObject
{
	Q_OBJECT

public:
	PCIControl(QObject *parent = nullptr);
	~PCIControl();

	void init();
	bool loadProfile(QString xmlFilePath);
	bool prepare();
	bool start();
	bool stop();
	//double *getDatas();
	void static BDAQCALL OnDataReadyEvent(void * sender, BfdAiEventArgs * args, void * userParam);
	void static BDAQCALL OnOverRunEvent(void * sender, BfdAiEventArgs * args, void * userParam);
	void static BDAQCALL OnCacheOverflowEvent(void * sender, BfdAiEventArgs * args, void * userParam);
	// This function is used to deal with 'StoppedEvent'.
	void static BDAQCALL OnStoppedEvent(void * sender, BfdAiEventArgs * args, void *userParam);

	void checkError(const ErrorCode &ret);

	int getIndex();

	ErrorCode ret;

signals:
	void getDataOnceOver(int index);

private:
	QString m_xmlConfigFilePath;
	WaveformAiCtrl* m_ctrl;
	QVector<double> m_dataVec;
	QVector<double *> m_dataPtrVec;
	double *m_datas = nullptr;
	bool isfinished = false;
	int m_count = 0;
	int m_index = 0;
};
